package p.sunmes.les.managers;

import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;

/*
 * SoundManager
 */
public class SoundM {

	boolean isMusicOn = true;
	boolean isSoundOn = true;
	Music current;
	String cPath = "";

	public void playSoundEffect(String path) {
		if (!isSoundOn) {
			return;
		}
		Sound sound = RM.instance().Asset().get(path, Sound.class);
		sound.play();
	}

	public void playMusic(String path) {
		if (!cPath.equals(path)) {
			if (current != null) {
				if (current.isPlaying()) {
					current.stop();
				}
			}
			current = RM.instance().Asset().get(path, Music.class);
			current.setLooping(true);
			cPath = path;
		}
		if (isMusicOn) {
			current.play();
		}
	}

	public void stopMusic() {
		if (current != null && current.isPlaying()) {
			current.stop();
		}
	}

	public void pauseMusic() {
		if (current != null && current.isPlaying()) {
			current.pause();
		}
	}

	public void resumeMusic() {
		if (!isMusicOn) {
			return;
		}
		if (current != null && !current.isPlaying()) {
			current.play();
		}
	}

	public void turnOnMusic() {
		if (isMusicOn) {
			return;
		}
		isMusicOn = true;
		if (current != null && !current.isPlaying()) {
			current.play();
		}
	}

	public void turnOffMusic() {
		if (!isMusicOn) {
			return;
		}
		isMusicOn = false;
		if (current != null && current.isPlaying()) {
			current.stop();
		}
	}

	public void turnOffSoundEffect() {
		if (!isSoundOn) {
			return;
		}
		isSoundOn = false;
	}

	public void turnOnSoundEffect() {
		if (isSoundOn) {
			return;
		}
		isSoundOn = true;
	}

	public void setSoundEffectOn(boolean isOn) {
		isSoundOn = isOn;
	}

	public void setMusicOn(boolean isOn) {
		isMusicOn = isOn;
	}

	//////////////
	private static SoundM _instance;

	public static SoundM instance() {
		if (_instance == null) {
			_instance = new SoundM();
		}
		return _instance;
	}

	public static void dispose() {
		if (_instance != null) {
			_instance = null;
		}
	}
}
